package forum.command;

import forum.entities.User;
import forum.services.UserService;

public class LogInCommand implements Command {

    private User user;
    private String email;
    private String password;
    private UserService userService = new UserService();

    @Override
    public void setParameters(String... args) {
        if (args.length != 2) {
            throw new IllegalArgumentException ("Incorrect number of arguments");
        }
        email = args[0];
        password = args[1];
    }

    @Override
    public void updateContext(CommandContext context) {
        context.setUser(user);
        context.setCategory(userService.getRootCategory());
    }

    @Override
    public void setContext(CommandContext context) {

    }

    @Override
    public void execute() {
    //    user = UserOperationsManager.signIn(email,password);
        user = userService.login(email, password);
    }

    @Override
    public String help() {
        return "Type 'login | %email% | %password%' to sign into forum";
    }
}
